package com.jiayi.weiphoto.keep;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class AuthoSharePreference {

	private final static String SHAREPREFERENCE_NAME = "AuthoSharePreference";
	
	private final static String KEY_TOKEN = "token";
	
	private final static String KEY_EXPIRES = "expires_in";
	
	private final static String KEY_OPENID = "open_id";
	
	private final static String KEY_OPENKEY = "open_key";
	
	private final static String KEY_UID= "uid";
	
		 
		 
	public AuthoSharePreference()
	{
		
	}
	
	public static boolean putToken(Context context, String token)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(KEY_TOKEN, token);
		
		return editor.commit();
	}
	
	public static String getToken(Context context)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		return sharedPreferences.getString(KEY_TOKEN, "");
	}
	
	public static boolean putExpires(Context context, String expires)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(KEY_EXPIRES, expires);
		
		return editor.commit();
	}
	
	public static String getExpires(Context context)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		return sharedPreferences.getString(KEY_EXPIRES, "");
	}

	public static boolean putUid(Context context, String uid)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(KEY_UID, uid);
		
		return editor.commit();
	}
	
	public static String getUid(Context context)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		return sharedPreferences.getString(KEY_UID, "");
	}
	
	public static boolean putOpenID(Context context, String openID)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(KEY_OPENID, openID);
		
		return editor.commit();
	}
	
	public static String getOpenID(Context context)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		return sharedPreferences.getString(KEY_OPENID, "");
	}
	
	public static boolean putOpenKey(Context context, String openKey)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(KEY_OPENKEY, openKey);
		
		return editor.commit();
	}
	
	public static String getOpenKey(Context context)
	{
		SharedPreferences sharedPreferences = context.getSharedPreferences(SHAREPREFERENCE_NAME, 0);
		return sharedPreferences.getString(KEY_OPENKEY, "");
	}
	
	public static void clearAll(Context context)
	{
		putToken(context, "");
		putExpires(context, "");
		putOpenID(context, "");
		putOpenKey(context, "");
		putUid(context, "");
	}
	
}
